package inits

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
	"main/config"
	"main/global"
)

func InitMysql() {
	var err error
	mc := config.Conf.MysqlConfig
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/2210a?charset=utf8mb4&parseTime=True&loc=Local",
		mc.User, mc.Pass, mc.Host, mc.Port)
	global.DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
		Logger: logger.Default.LogMode(logger.Error),
	})
	if err != nil {
		panic(err)
	}
	fmt.Println("mysql init success:", dsn)
}
